<!DOCTYPE html>
<html lang=zh>
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform">
  <meta http-equiv="Cache-Control" content="no-siteapp">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000">
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top">
  
  
  <title>GitLab-CI搭建持续集成环境 | 王竹兴 | Blob</title>
  <meta name="description" content="什么是持续集成   概述 ​	持续集成（Continuous Integration，简称CI）指的是，频繁地（一天多次）将代码集成到主干。 ​	GitLab CI是 GitLab 提供的持续集成服务，只要在你的仓库根目录 创建一个.gitlab-ci.yml 文件， 并为该项目指派一个Runner，当有合并请求或者 push的时候就会触发build。 ​	.gitlab-ci.yml 文件定义">
<meta name="keywords" content="持续集成">
<meta property="og:type" content="article">
<meta property="og:title" content="GitLab-CI搭建持续集成环境">
<meta property="og:url" content="http://zhulao.gitee.io/blog/2019/04/18/GitLab-CI搭建持续集成环境/index.html">
<meta property="og:site_name" content="王竹兴 | Blog">
<meta property="og:description" content="什么是持续集成   概述 ​	持续集成（Continuous Integration，简称CI）指的是，频繁地（一天多次）将代码集成到主干。 ​	GitLab CI是 GitLab 提供的持续集成服务，只要在你的仓库根目录 创建一个.gitlab-ci.yml 文件， 并为该项目指派一个Runner，当有合并请求或者 push的时候就会触发build。 ​	.gitlab-ci.yml 文件定义">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g29eus17saj20rs0ekafi.jpg">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g29erkm98fj20rs0iidih.jpg">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g29eu75mj3j20rs0jgtbf.jpg">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g29ez1mvnuj20rs0fmq6r.jpg">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g29hakohvbj20rs0awacd.jpg">
<meta property="og:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g29hb40edxj20rs0didk0.jpg">
<meta property="og:updated_time" content="2019-04-27T14:13:05.601Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="GitLab-CI搭建持续集成环境">
<meta name="twitter:description" content="什么是持续集成   概述 ​	持续集成（Continuous Integration，简称CI）指的是，频繁地（一天多次）将代码集成到主干。 ​	GitLab CI是 GitLab 提供的持续集成服务，只要在你的仓库根目录 创建一个.gitlab-ci.yml 文件， 并为该项目指派一个Runner，当有合并请求或者 push的时候就会触发build。 ​	.gitlab-ci.yml 文件定义">
<meta name="twitter:image" content="http://ww1.sinaimg.cn/large/929ea2a1gy1g29eus17saj20rs0ekafi.jpg">
  <!-- Canonical links -->
  <link rel="canonical" href="http://zhulao.gitee.io/blog/2019/04/18/GitLab-CI搭建持续集成环境/index.html">
  
    <link rel="alternate" href="/atom.xml" title="王竹兴 | Blog" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png" type="image/x-icon">
  
  <link rel="stylesheet" href="/blog/css/style.css">
  
  
  
  
</head>


<body class="main-center" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://github.com/wzx3" target="_blank">
          <img class="img-circle img-rotate" src="/blog/images/avatar.jpeg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">王竹兴</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md"></h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> XiaMen, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索">
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech>
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav menu-highlight">
        
        
        <li class="menu-item menu-item-home">
          <a href="/blog/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-repository">
          <a href="/blog/repository">
            
            <i class="icon icon-project"></i>
            
            <span class="menu-title">项目</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">关于</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/wzx3" target="_blank" title="Github" data-toggle="tooltip" data-placement="top"><i class="icon icon-github"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle="tooltip" data-placement="top"><i class="icon icon-rss"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>人生最快意的事情之一, 就是你比别人牛逼, 然后静静的看别人在你面前装逼。</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/便签/">便签</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/教程/">教程</a><span class="category-list-count">22</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/游记/">游记</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/随笔/">随笔</a><span class="category-list-count">6</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="/blog/tags/DL/" style="font-size: 13.25px;">DL</a> <a href="/blog/tags/Debug/" style="font-size: 13.5px;">Debug</a> <a href="/blog/tags/Doc/" style="font-size: 13px;">Doc</a> <a href="/blog/tags/Hexo/" style="font-size: 13.25px;">Hexo</a> <a href="/blog/tags/Links/" style="font-size: 13px;">Links</a> <a href="/blog/tags/Linux/" style="font-size: 13.25px;">Linux</a> <a href="/blog/tags/Mac/" style="font-size: 13px;">Mac</a> <a href="/blog/tags/bazel/" style="font-size: 13px;">bazel</a> <a href="/blog/tags/c-c/" style="font-size: 13.75px;">c/c++</a> <a href="/blog/tags/git/" style="font-size: 13px;">git</a> <a href="/blog/tags/rst/" style="font-size: 13px;">rst</a> <a href="/blog/tags/scripts/" style="font-size: 13.75px;">scripts</a> <a href="/blog/tags/ssh/" style="font-size: 13px;">ssh</a> <a href="/blog/tags/国学经典/" style="font-size: 13px;">国学经典</a> <a href="/blog/tags/持续集成/" style="font-size: 13.25px;">持续集成</a> <a href="/blog/tags/科幻小说/" style="font-size: 14px;">科幻小说</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/05/">五月 2019</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/04/">四月 2019</a><span class="archive-list-count">10</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/03/">三月 2019</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/02/">二月 2019</a><span class="archive-list-count">10</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/随笔/">随笔</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/26/读论语/" class="title">读论语</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-26T01:45:07.000Z" itemprop="datePublished">2019-05-26</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/随笔/">随笔</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/20/读变型战争/" class="title">读变型战争</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-20T15:51:57.000Z" itemprop="datePublished">2019-05-20</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/随笔/">随笔</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/20/读星际远征/" class="title">读黑客横行</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-20T15:40:09.000Z" itemprop="datePublished">2019-05-20</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/教程/">教程</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/15/代码格式化工具-clang-format/" class="title">代码格式化工具:clang-format</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-15T14:39:51.000Z" itemprop="datePublished">2019-05-15</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/教程/">教程</a>
              </p>
              <p class="item-title">
                <a href="/blog/2019/05/12/Linux-疑难杂症/" class="title">Linux 疑难杂症</a>
              </p>
              <p class="item-date">
                <time datetime="2019-05-12T02:50:29.000Z" itemprop="datePublished">2019-05-12</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">文章目录</h3>
      <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#什么是持续集成"><span class="toc-number">1.</span> <span class="toc-text"> 什么是持续集成</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#搭建持续集成环境"><span class="toc-number">2.</span> <span class="toc-text"> 搭建持续集成环境</span></a></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <div class="content">
  <article id="post-GitLab-CI搭建持续集成环境" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      GitLab-CI搭建持续集成环境
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/blog/2019/04/18/GitLab-CI搭建持续集成环境/" class="article-date">
	  <time datetime="2019-04-18T13:02:58.000Z" itemprop="datePublished">2019-04-18</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/blog/categories/教程/">教程</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/blog/tags/持续集成/">持续集成</a>
  </span>


        
	<span class="article-read hidden-xs">
	    <i class="icon icon-eye-fill" aria-hidden="true"></i>
	    <span id="busuanzi_container_page_pv">
			<span id="busuanzi_value_page_pv">0</span>
		</span>
	</span>


        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blog/2019/04/18/GitLab-CI搭建持续集成环境/#comments" class="article-comment-link">评论</a></span>
        
	
		<span class="post-wordcount hidden-xs" itemprop="wordCount">字数统计: 1,037(字)</span>
	
	
		<span class="post-readcount hidden-xs" itemprop="timeRequired">阅读时长: 5(分)</span>
	

      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <h4 id="什么是持续集成"><a class="markdownIt-Anchor" href="#什么是持续集成"></a> 什么是持续集成</h4>
<ul>
<li>
<p>概述</p>
<p>​	<strong>持续集成</strong>（<strong>Continuous Integration</strong>，简称<code>CI</code>）指的是，<strong>频繁地（一天多次）将代码集成到主干</strong>。</p>
<p>​	<strong>GitLab CI</strong>是 <strong>GitLab</strong> 提供的持续集成服务，只要在你的仓库根目录 创建一个<code>.gitlab-ci.yml</code> 文件， 并为该项目指派一个<strong>Runner</strong>，<strong>当有合并请求或者 push的时候就会触发build</strong>。</p>
<p>​	<code>.gitlab-ci.yml</code> 文件<strong>定义GitLab runner要做哪些操作</strong>。 默认有3个[stages(阶段)]: <strong>build</strong>、<strong>test</strong>、<strong>deploy</strong>。</p>
</li>
<li>
<p>优点</p>
<ul>
<li>可以<strong>快速发现错误，定位错误</strong>也比较容易</li>
<li><strong>防止分支大幅偏离主干</strong>。代码集成到主干之前，必须通过自动化测试。只要有一个测试用例失败，就不能集成</li>
<li>持续交付、持续部署
<ul>
<li><strong>持续交付</strong>（<strong>Continuous delivery</strong>）指的是，频繁地将软件的新版本，交付给质量团队或者用户，以供评审。如果评审通过，代码就进入生产阶段。</li>
<li><strong>持续部署</strong>（<strong>Continuous deployment</strong>）是持续交付的下一步，指的是代码通过评审以后，自动部署到生产环境。</li>
</ul>
</li>
</ul>
</li>
<li>
<p>持续集成系统的组成</p>
<ul>
<li><strong>一个自动构建过程</strong>，包括<strong>自动编译、分发、部署和测试</strong>等。</li>
<li><strong>一个代码存储库</strong>，即需要<strong>版本控制</strong>软件来保障代码的可维护性，同时作为构建过程的素材库。</li>
<li><strong>一个持续集成服务器</strong>。</li>
</ul>
</li>
</ul>
<h4 id="搭建持续集成环境"><a class="markdownIt-Anchor" href="#搭建持续集成环境"></a> 搭建持续集成环境</h4>
<ul>
<li>
<p>登录 <a href="https://gitlab.com/" target="_blank" rel="noopener"><strong>GitLab</strong></a> 新建一个空的工程(如<code>gitlab-ci-test</code>)</p>
</li>
<li>
<p>左侧<strong>工具栏</strong>依次选择: <strong>设置</strong> -&gt; <strong>CI/CD</strong> 进行手动设置指定运行器</p>
<p><img src="http://ww1.sinaimg.cn/large/929ea2a1gy1g29eus17saj20rs0ekafi.jpg" alt></p>
</li>
<li>
<p><strong>配置专用 Runner</strong></p>
<ul>
<li>
<p><strong>安装 GitLab Runner</strong></p>
<blockquote>
<p>各平台安装教程可至<a href="https://docs.gitlab.com/runner/install/" target="_blank" rel="noopener"><strong>官网教程</strong></a>查看, 这里仅对<code>Linux</code>平台进行介绍。</p>
</blockquote>
<p>在Linux平台上搭建有两种方式</p>
<ol>
<li>虚拟机。如macOS上的<strong>Parallels Desktop</strong></li>
<li>Docker。</li>
</ol>
<ul>
<li>
<p>第一步，下载</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 64位机器</span></span><br><span class="line">sudo wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64</span><br></pre></td></tr></table></figure>
</li>
<li>
<p>第二步，加执行权限</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo chmod +x /usr/local/bin/gitlab-runner</span><br></pre></td></tr></table></figure>
</li>
<li>
<p>第三步，下载<strong>docker</strong> (<strong>可选</strong>，可不执行)</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl -sSL https://get.docker.com/ | sh</span><br></pre></td></tr></table></figure>
</li>
<li>
<p>第四步，创建一个 <strong>gitlab-ci</strong> 用户</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash</span><br></pre></td></tr></table></figure>
</li>
<li>
<p>第五步，启动runner</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> install</span></span><br><span class="line">sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> run</span></span><br><span class="line">sudo gitlab-runner start</span><br></pre></td></tr></table></figure>
</li>
</ul>
</li>
<li>
<p><strong>注册 Runner</strong> (绑定持续集成工程)</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo gitlab-runner register</span><br></pre></td></tr></table></figure>
<p>将会依次提示</p>
<ul>
<li>
<p><strong>Please enter the gitlab-ci coordinator URL (e.g. <a href="https://gitlab.com" target="_blank" rel="noopener">https://gitlab.com</a> )</strong></p>
<p>输入gitlab-ci的坐标地址:</p>
<p><img src="http://ww1.sinaimg.cn/large/929ea2a1gy1g29erkm98fj20rs0iidih.jpg" alt></p>
</li>
<li>
<p><strong>Please enter the gitlab-ci token for this runner</strong></p>
<p>输入你的注册令牌:</p>
<p><img src="http://ww1.sinaimg.cn/large/929ea2a1gy1g29eu75mj3j20rs0jgtbf.jpg" alt></p>
</li>
<li>
<p><strong>Please enter the gitlab-ci description for this runner</strong></p>
<p>为你的Runner设置描述信息, 看个人喜好, 这里设置 <code>my-first-runner</code></p>
</li>
<li>
<p><strong>Please enter the gitlab-ci tags for this runner (comma separated):</strong></p>
<p>为你的Runner设置标签信息, 之后<code>.gitlab-ci.yml</code>可配置不同的<strong>tag</strong>来跑不同的Runner, 这里设置<code>Local-Ubuntu-16-04</code></p>
</li>
<li>
<p><strong>Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker parallels, virtualbox, docker-ssh, shell:</strong></p>
<p>为你的Runner设置执行器, 这里设置<code>shell</code></p>
</li>
</ul>
<p>测试完毕后<strong>刷新</strong>我们的gitlab工程, 可以看到注册后的Runner</p>
<p><img src="http://ww1.sinaimg.cn/large/929ea2a1gy1g29ez1mvnuj20rs0fmq6r.jpg" alt></p>
<p>发现这边有个感叹号, 这是由于我们的测试工程未进行标记, 可以进入箭头指向的设置按钮</p>
<p>![image-20190420212235003](/Users/wangzhuxing/Library/Application Support/typora-user-images/image-20190420212235003.png)</p>
<p>勾选<strong>允许运行未标记的作业</strong>, <strong>保存修改</strong>。</p>
</li>
</ul>
</li>
<li>
<p>编写最简单的测试工程</p>
<ul>
<li>
<p>工程目录</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">├── gitlab-ci-test</span><br><span class="line">    ├── .gitlab-ci.yml</span><br><span class="line">    ├── build.sh</span><br><span class="line">    ├── clean.sh</span><br><span class="line">    ├── CMakeLists.txt</span><br><span class="line">    ├── main.cpp</span><br><span class="line">    ├── README.md</span><br><span class="line">	└── run.sh</span><br></pre></td></tr></table></figure>
<p>main.cpp简单打印<code>HelloWorld!</code></p>
</li>
</ul>
</li>
<li>
<p>配置<code>.gitlab-ci.yml</code></p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">before_script:</span></span><br><span class="line"><span class="bullet">  -</span> <span class="string">echo</span> <span class="string">"Start gitlab-ci deploy"</span></span><br><span class="line"><span class="attr">after_script:</span></span><br><span class="line"><span class="bullet">  -</span> <span class="string">echo</span> <span class="string">"End gitlab-ci deploy"</span></span><br><span class="line"></span><br><span class="line"><span class="attr">stages:</span></span><br><span class="line"><span class="bullet">  -</span> <span class="string">build</span></span><br><span class="line"><span class="bullet">  -</span> <span class="string">test</span></span><br><span class="line"><span class="bullet">  -</span> <span class="string">deploy</span></span><br><span class="line"></span><br><span class="line"><span class="attr">build:</span></span><br><span class="line"><span class="attr">  stage:</span> <span class="string">build</span></span><br><span class="line"><span class="attr">  tags:</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">Local-Ubuntu-16-04</span></span><br><span class="line"><span class="attr">  script:</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">echo</span> <span class="string">"Now, do build"</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">sh</span> <span class="string">build.sh</span></span><br><span class="line"><span class="attr">  only:</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">develop</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">master</span></span><br><span class="line"></span><br><span class="line"><span class="attr">test:</span></span><br><span class="line"><span class="attr">  stage:</span> <span class="string">test</span></span><br><span class="line"><span class="attr">  tags:</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">Local-Ubuntu-16-04</span></span><br><span class="line"><span class="attr">  script:</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">echo</span> <span class="string">"Now, do test"</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">sh</span> <span class="string">build.sh</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">sh</span> <span class="string">run.sh</span></span><br><span class="line"><span class="attr">  only:</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">develop</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">master</span></span><br><span class="line"></span><br><span class="line"><span class="attr">deploy:</span></span><br><span class="line"><span class="attr">  stage:</span> <span class="string">deploy</span></span><br><span class="line"><span class="attr">  tags:</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">Local-Ubuntu-16-04</span></span><br><span class="line"><span class="attr">  script:</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">echo</span> <span class="string">"Now, do deploy"</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">sh</span> <span class="string">clean.sh</span></span><br><span class="line"><span class="attr">  only:</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">develop</span></span><br><span class="line"><span class="bullet">    -</span> <span class="string">master</span></span><br></pre></td></tr></table></figure>
</li>
<li>
<p>推送到远程仓库</p>
</li>
<li>
<p>查看持续集成结果</p>
<p><img src="http://ww1.sinaimg.cn/large/929ea2a1gy1g29hakohvbj20rs0awacd.jpg" alt></p>
<p><img src="http://ww1.sinaimg.cn/large/929ea2a1gy1g29hb40edxj20rs0didk0.jpg" alt></p>
</li>
</ul>
<blockquote>
<ul>
<li>参考链接
<ul>
<li><a href="https://www.jianshu.com/p/705428ca1410" target="_blank" rel="noopener">基于Gitlab CI搭建持续集成环境</a></li>
</ul>
</li>
</ul>
</blockquote>

      
    </div>
    <div class="article-footer">
      <!-- <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="http://zhulao.gitee.io/blog/2019/04/18/GitLab-CI搭建持续集成环境/" title="GitLab-CI搭建持续集成环境" target="_blank" rel="external">http://zhulao.gitee.io/blog/2019/04/18/GitLab-CI搭建持续集成环境/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://github.com/wzx3" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/blog/images/avatar.jpeg" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://github.com/wzx3" target="_blank"><span class="text-dark">王竹兴</span><small class="ml-1x"></small></a></h3>
        <div></div>
      </div>
    </figure>
  </div>
</div>
 -->

    </div>
  </article>
  
    
  <section id="comments">
  	
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/blog/2019/04/20/Docker教程/" title="Docker教程"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/blog/2019/04/17/BAT脚本常用命令/" title="BAT脚本常用命令"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="文章目录" role="button">
        <span>[&nbsp;</span><span>文章目录</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat,facebook,twitter" data-mobile-sites="weibo,qq,qzone"></div>
    
  </div>
  </div>
</nav>
  


</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/wzx3" target="_blank" title="Github" data-toggle="tooltip" data-placement="top"><i class="icon icon-github"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle="tooltip" data-placement="top"><i class="icon icon-rss"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>
<script src="/blog/js/plugin.min.js"></script>
<script src="/blog/js/application.js"></script>

    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/blog/',
        CONTENT_URL: '/blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>
<script src="/blog/js/insight.js"></script>





   
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





   






</body>
</html>